<template>
  <div class="workMent">
    <el-table :data="dataTable" v-loading="loading"  border style="width: 100%">
    <el-table-column prop="id" label="id" align="center"></el-table-column>
    <el-table-column prop="userId" label="班级" align="center"></el-table-column>
    <el-table-column prop="title" label="作业名称" align="center"></el-table-column>
    <el-table-column prop="completed" label="完成情况" align="center"></el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[5, 10, 20, 50,100]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import { getWorks } from '@/service/api/login'
  export default {
    data() {
      return {
        dataTable:[],
        page:1,
        size:10,
        total:0,
        loading:true
      }
    },
    methods:{
      handleSizeChange(val) {
        this.page = 1
        this.size =val
        this.getData()
      },
      handleCurrentChange(val) {
        this.page = val
        this.getData()
      },
     async getData(){
       const { data:res } =await getWorks(this.page,this.size)
       console.log(res)
       this.dataTable = res.data
       this.total = res.total
       this.dataTable.forEach(item => {
        item.completed = item.completed ? '是':'否'
       })
       this.loading = false
      }
    },
    created(){
      this.getData()
    }
  }
</script>

<style lang="scss" scoped>
.workMent{
  .el-pagination{
   text-align: right;
   margin-top: 15px;
  }
}
</style>